package com.atguigu.dga.scheduler;


import com.atguigu.dga.governance.bean.GovernanceAssessDetail;
import com.atguigu.dga.governance.service.GovernanceAssessDetailService;
import com.atguigu.dga.governance.service.GovernanceAssessGlobalService;
import com.atguigu.dga.governance.service.GovernanceAssessTableService;
import com.atguigu.dga.governance.service.GovernanceAssessTecOwnerService;
import com.atguigu.dga.meta.service.TableMetaInfoService;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class AssessScheduler {

    @Autowired
    TableMetaInfoService tableMetaInfoService;

    @Autowired
    GovernanceAssessDetailService governanceAssessDetailService;


    @Autowired
    GovernanceAssessTableService governanceAssessTableService;

    @Autowired
    GovernanceAssessTecOwnerService governanceAssessTecOwnerService;

    @Autowired
    GovernanceAssessGlobalService governanceAssessGlobalService;

    @Value("${assess.schema-names}")
    String assessSchemaNames;



    @Scheduled(cron = "0/30 6 6 6 * *")
    public void exec() throws  Exception{
        System.out.println("  定时任务开始执行执行： "+new Date());
        mainAssess();
    }




    public void   mainAssess() throws  Exception{
       // String assessDate = DateFormatUtils.format(new Date(), "yyyy-MM-dd");
        String assessDate="2023-05-02";
        String[] schemaNameArr = assessSchemaNames.split(",");
        for (String schemaName : schemaNameArr) {
            // 1 提取元数据
            tableMetaInfoService.initTableMeta(assessDate,schemaName);
            // 2  考评
            governanceAssessDetailService.mainAssess(assessDate);
            // 3  统计分数
            governanceAssessTableService.genAssessTable(assessDate);
            governanceAssessTecOwnerService.genAssessTecOwner(assessDate);
            governanceAssessGlobalService.genAssessGlobal(assessDate);

        }


    }



}
